#include <ctime>
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;


void bubbleSort(int a[], int listLength) {
    for (int i = 0; i < listLength; i++)
    {
        bool flag = true;
        for (int j = 0; j < listLength - (i + 1); j++)
        {
            if (a[j] > a[j + 1])
            {
                flag = false;
                swap (a[j], a[j + 1]);
            }
        }
        if (flag)
        {
            break;
        }
    }

}


void read_from_file(const char *filename, int a[], int length) {
    ifstream fin(filename);
    for(int i=0; i < length; i++) {
        fin >> a[i];
    }
}

int main()
{
#define LEN 5000
int a[LEN];
read_from_file("m1_sorted.txt",a,LEN);
unsigned int start = clock();
bubbleSort(a,LEN);
unsigned int finish = clock();
unsigned int work = finish - start;
cout<<"m1_sorted " << work << " milliseconds \n";

read_from_file("m2_reverse.txt",a,LEN);
unsigned int start2 = clock();
bubbleSort(a,LEN);
unsigned int finish2 = clock();
unsigned int work2 = finish2 - start2;
cout<<"m2_revers " << work2 << " milliseconds \n";

read_from_file("m3_shuffle.txt",a,LEN);
unsigned int start3 = clock();
bubbleSort(a,LEN);
unsigned int finish3 = clock();
unsigned int work3 = finish3 - start3;
cout<<"m3_shuffle " << work3 << " milliseconds \n";
}
